﻿using DataConvertTool;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace DataConvertToolTester
{
    class Program
    {
        static void Main(string[] args)
        {


            #region byte转二进制字符串
            //byte val = 0xFF;   //byte: 0-255

            //byte val = 7;
            //string binaryStr = DataConvert.ConvertByteToBinaryStr(val);
            //Console.WriteLine(binaryStr);
            #endregion

            #region byte转8进制字符串
            //c#前面字面量:8进制077表示十进制63
            //byte val1 = 63;
            //string octStr = DataConvert.ConvertByteToOctalStr(val1);
            //Console.WriteLine(octStr);
            #endregion

            #region byte转16进制字符串
            //byte val1 = 15;
            //string hexStr=DataConvert.ConvertByteToHexStr(val1);
            //Console.WriteLine(hexStr);
            #endregion

            #region UInt16转十六进制字符串
            //ushort val1 = 0xFFFF;
            //ushort val1 = 65535;
            //string hexStr = DataConvert.ConvertUint16ToHexStr(val1);
            //Console.WriteLine(hexStr);
            #endregion

            #region float转二进制字符串
            //float val1 = 15F;
            //string floatStr = DataConvert.ConvertFloat32ToBinaryStr(val1);
            //Console.WriteLine(floatStr);
            #endregion

            #region double转二进制字符串
            //double val2 = 15D;
            //string doubleStr = DataConvert.ConvertFloat64ToBinaryStr(val2);
            //Console.WriteLine(doubleStr);
            #endregion

            #region float转16进制字符串
            //float val1 = 15F;
            //string floatStr = DataConvert.ConvertFloat32ToHexStr(val1);
            //Console.WriteLine(floatStr);
            #endregion

            #region double转16进制字符串
            //double val2 = 15D;
            //string doubleStr = DataConvert.ConvertFloat64ToHexStr(val2);
            //Console.WriteLine(doubleStr);
            #endregion

            #region 2进制字符串转byte
            //bool result = false;
            //string errorMsg = string.Empty;
            //string str = "111";
            //byte val = DataConvert.ConvertBinaryStrToByte(str, out result, out errorMsg);
            //Console.WriteLine(val);
            #endregion

            #region 16进制字符串转byte
            //bool result = false;
            //string errorMsg = string.Empty;
            //string str = "0XFF";
            //byte val = DataConvert.ConvertHexStrToByte(str, out result, out errorMsg);
            //Console.WriteLine(val);
            #endregion

            #region 十六进制字符串数组转Byte数组
            //string str = "FF 01 02 03 FF";
            //string[] byteStrs = str.Split(' ');
            //byte[] byteArr = DataConvert.ConvertHexStringArraytrToByteArray(byteStrs, out bool result, out string errorStr);// [255 1 2 3 255]
            //Console.WriteLine($@"{result},{errorStr}");
            #endregion

            #region 字节数组转16进制字符串
            byte[] bytes = { 0XFF, 0X01, 0X02, 0X03, 0XFF };
            string hexStr = DataConvert.ConvertByteArrayToHexStringArray(bytes, out bool result, out string errorStr);
            if (result)
            {
                Console.WriteLine(hexStr);
            }
            else
            {
                Console.WriteLine(errorStr);
            }
           
            #endregion




            Console.ReadKey();


        }
    }
}
